package com.lsk.order.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.lsk.model.Bean.Order;
import com.lsk.model.Bean.Product;
import com.lsk.order.api.ProductApi;
import com.lsk.order.properties.CommonProperties;
import com.lsk.order.properties.ConfigProperties;
import com.lsk.order.properties.TestProperties;
import com.lsk.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class ConfigController {
    @Autowired
    private ConfigProperties configProperties;
    @Autowired
    private TestProperties testProperties;
    @Autowired
    private CommonProperties commonProperties;
    @Autowired
    private ProductApi productApi;
    @Autowired
    private OrderService orderService;

    /**
     * 创建订单
     * @return
     */
    @GetMapping("/getOrder")
    public Order createOrder(@RequestParam("orderId") Long OrderId, @RequestParam("userId") Long UserId) {
       Order order=orderService.getOrder(OrderId, UserId);
        //todo 远程调用商品服务
        Product product = productApi.getProduct(order.getProductId());
        if (product != null) {
            order.setProduct(product);
        }
        return order;
    }

    @GetMapping("/config")
    public String getConfig() {
        System.out.println("order.timeOut:"+configProperties.getTimeout());
        System.out.println("order.desc:"+configProperties.getDesc());
        return "service-order-config";
    }

    @GetMapping("/test")
    public String getTest() {
        System.out.println("test.a:"+testProperties.getA());
        System.out.println("test.b:"+testProperties.getB());
        System.out.println("test.c:"+testProperties.getC());
        return "service-order-test";
    }

    @GetMapping("/common")
    public String getCommon() {
        System.out.println("common.user:"+commonProperties.getUser());
        System.out.println("common.password:"+commonProperties.getPassword());
        return "service-order-common";
    }
}
